import 'dart:convert';

class SpaceModel {
  String? parkingSpaceName;
  String? plateNum;
  int? pointType;
  int? parkingSpaceId;
  int? type;
  int? parkingLotId;
  int? floorId;
  int? areaId;
  int? parkingSpaceStatus;
  int? sensorId;
  int? cameraId;
  int? cameraShow;
  int? fireEquipmentId;
  double? x;
  double? y;
  double? width;
  double? height;
  bool? select;
  SpaceModel({this.parkingSpaceName, this.pointType,this.parkingSpaceId,this.type,this.parkingLotId,
    this.floorId,this.areaId,this.parkingSpaceStatus,this.sensorId,this.cameraId,this.cameraShow,this.fireEquipmentId,
  this.x,this.y,this.width,this.height,this.plateNum, this.select=false,
  });

  SpaceModel.fromJson(Map<String, dynamic> jsonData) {
    parkingSpaceName = jsonData['parkingSpaceName'];
    pointType = jsonData['pointType'];
    type = jsonData['type'];
    parkingLotId = jsonData['parkingLotId'];
    floorId = jsonData['floorId'];
    areaId = jsonData['areaId'];
    parkingSpaceStatus = jsonData['parkingSpaceStatus'];
    parkingSpaceId = jsonData['parkingSpaceId'];
    sensorId = jsonData['sensorId'];
    cameraId = jsonData['cameraId'];
    cameraShow = jsonData['cameraShow'];
    fireEquipmentId = jsonData['fireEquipmentId'];
    plateNum = jsonData['plateNum'];
    // print( jsonData['parkingSpaceName']);
    select = false;

    List pointArr = json.decode(jsonData['pointArr']);
    double minX = 1000000;
    double minY = 1000000;
    double maxX = 0;
    double maxY = 0;

    pointArr.forEach((element) {
      Point point = Point.fromJson(element);
      if(minX>point.x!){
        minX = point.x!;
      }
      if(maxX<point.x!){
        maxX = point.x!;
      }
      if(minY>point.y!){
        minY = point.y!;
      }
      if(maxY< point.y!){
        maxY = point.y!;
      }
    });

    x = minX;
    y = minY;
    height = maxX - minX;
    width  = maxY - minY;

  }
}

class Point {
  //当前屏幕计算的值
  double? x;
  double? y;
  Point({this.x,this.y});

  Point.fromJson(Map<String, dynamic> jsonData) {
    x = jsonData['x'].toDouble();
    y = jsonData['y'].toDouble();
  }
}
